/*2018-05-11新增内容*/

/*2018-04-28点赞动画*/
var CreateLove = function(){
	var self;
}
	
CreateLove.prototype={
	
	init:function(){
		var mLove =  $("<div class='lovebox'><img src='images/love.png'/></div>");
		$(".mbox").append(mLove);
		self.box = mLove;
		this.endH =  $(".mbox").height();
		this.endW = $(".mbox").width();
		
	},
	move:function(){
		var randomY = (Math.random()*(this.endH-400))+100;
		var randomX = Math.random()*this.endW+16;
		$(self.box).animate({bottom:randomY,right:randomX,height:"80px",width:"80px",opacity:"0"},4000,function(){
			$(this).remove();
		});
	}
}


/*2018-05-29婚庆动画调整*/
/*2018-05-08气球动画*/
	function qqdh(){
		$(".qqdh").append($(".adh:first-child").clone(true).addClass("show_dh").removeClass(".adh"));
		$(".show_dh").show();
		$(".qqdh .show_dh div.qq1").addClass("mykey").animate({bottom:"100%"},{ duration:3500,easing:"easeInQuad"})
		$(".qqdh .show_dh div.qq2").addClass("mykey").animate({bottom:"100%"},{ duration:3750,easing:"easeInQuad"})
		$(".qqdh .show_dh div.qq3").addClass("mykey").animate({bottom:"100%"},{ duration:4000,easing:"easeInQuad",complete:function(){
				$(this).parent(".show_dh").remove();
			}
		})
	}


/*2018-05-08接吻动画背景*/
var CreateHuab = function(){
	var self;
}
	
CreateHuab.prototype={
	init:function(){
		var mHuab =  $("<div class='mHuab'><img src='images/huab_03.png'/></div>");
		$(".jwdh").append(mHuab);
		self.box = mHuab;
		this.endH = Math.random()*$(".jwdh").height()+300;
		this.endW =  $(".jwdh").width();
		var x = Math.random()*this.endW;
		var mWidth = (Math.random()*6+3);
		var deg = Math.random()*180;
		var endDeg=  deg+180+"deg";
		$(self.box).css("left",x+"px");
		$(self.box).css("width",mWidth+"%");
		$(self.box).css("transform","rotate("+deg+"deg)")
	},
	move:function(){
		var randomY = this.endH;
		$(self.box).animate({'top':randomY,'opacity':"0"},8000,"linear",function(){
			$(this).remove();
		});
	}
}

/*接吻移动*/

	var timer2;
	function jwdh(){
		clearInterval(timer2);
			timer2 = setInterval(function(){
				var aHuab = new CreateHuab();
				aHuab.init();
				aHuab.move();
				
			},100);
		$(".jwdh").show();
		$(".jwdh").append($(".ajw:first-child").clone(true).addClass("show_jw"));
		$(".show_jw").show();
		$(".jwdh .show_jw .boy").animate({'right':"21%"},4000);
		$(".jwdh .show_jw .girl").animate({'left':"21%"},4000,function(){
			var myself = this;
			setTimeout(function(){
				$(myself).parent(".show_jw").animate({opacity:0},500,function(){
					$(myself).parent(".show_jw").remove();
					if ($(".jwdh .show_jw").size()=="0") {
						$(".jwdh").hide();
						clearInterval(timer2);
					
						$(".jwdh .mHuab").remove();
					}
				})

			},1000)	
		});
	}

/*送子鹤*/

	function szdh(){
		$(".szdh").append( $(".asz:first-child").clone(true).addClass("show_asz"));
		$(".show_asz:last-of-type").show();
		$(".show_asz:last-of-type").animate({top:0},3000);
		$(".szdh .show_asz .szh5").animate({left:"29%"},3000);
		$(".szdh .show_asz .szh6").animate({left:"55%"},3000,function(){
			 var myself = this;
			 $(myself).parent(".show_asz").children(".szh4").animate({left:"3%"},1000,function(){
				setTimeout(function(){
					$(myself).parent(".show_asz").children(".szh7").animate({bottom:"-10%"},500,function(){
						
					})
					$(myself).parent(".show_asz").animate({opacity:0},1000,function(){
						$(myself).parent(".show_asz").remove();	
						if ($(".szdh .show_asz").size()==0) {
							$(".szdh").hide();
						}
					})
				},500)
			});
		});
		
	}

/*鲜花飘动*/

var CreateHua = function(){
	var self;
}
	
CreateHua.prototype={
	init:function(){
		var mHuab =  $("<div class='xh2'><img src='images/huaban_03.png'/></div>");
		$(".axh").append(mHuab);
		self.box = mHuab;
		var mtop = parseInt(42);
		$(mHuab).css("top",mtop+"%")
		this.endH = Math.random()*$(".axh").height()+300;
		this.endW =  $(".axh").width();
		this.x = Math.random()*this.endW+100; 
		var mWidth = (Math.random()*5+3);
		var deg = Math.random()*180;

		$(self.box).css("width",mWidth+"%");
		$(self.box).css("transform","rotate("+deg+"deg)")
	},
	move:function(){
		var randomX=this.x;
		var randomY = this.endH;
		
		$(self.box).animate({'top':randomY,'right':randomX,'opacity':"0"},5000,"linear",function(){
			$(this).remove();
		});
	}
}

var timer3; 
function xhdh(){
	clearInterval(timer3);
	timer3 = setInterval(function(){
		var bHuab = new CreateHua();
		bHuab.init();
		bHuab.move();
		
	},300);
	
	
	$(".xhdh .axh").append($(".xhdh .axh .xh1:first-child").clone(true).addClass("show_xh").removeClass(".xh1"));
	$(".xhdh .axh .show_xh").animate({bottom:"22%"},4000);
	setTimeout(function(){
		
		$(".xhdh .axh .show_xh").animate({opacity:0},1000,function(){
			$(this).remove();
			if ($(".show_xh").length==0) {
				$(".xhdh").hide();
				clearInterval(timer3);
			}
		})
		
	},4000)
}
/*2018-05-29婚庆动画调整end*/


var selGoodsId=null;
initGiftList();
function initGiftList(){
	$(".liwu_list").hide();
	$(".liwu_list").html('');
	$.ajax({    
		url:"../proxy/galaxy/v1/goods/wx/wedding_gift",
		type:'get',
		dataType:'json',
        contentType: 'application/json;charset=utf-8',
		async:true,//需要获取后台返回的msgId
		success:function(data){
			var list = data;
			for(var i=0;i<list.length;i++){
				var goods = list[i];
				var gift = $('#giftDemo').clone();
				gift.attr("id",goods.goodsId);
				gift.find("img:eq(0)").attr("src","images/liwu"+(i+1)+".png");
				gift.find(".name").html(goods.name);
				gift.find(".jg").html(goods.price);
				gift.show();
				$('.liwu_list').append(gift);
			}
			$(".liwu_list li").click(function(){
				selGoodsId = $(this).attr("id");
				$(this).addClass("now").siblings("li").removeClass("now");
				$(".xzdh button em").text("金额 "+ $(this).find(".jg").text());
			})
	   	},
	   	complete:function(){
	   		$(".liwu_list").show();
			//$(".xzdh").slideDown(500);
	   	},
		error:function(e){
			console.error(e);
			alert("系统忙，请稍后再试");
		}
	});
}
/*礼物列表*/
$(".liwu").click(function(){
	$(".xzdh").slideDown(500);
})




$(".xzdh h2 span").click(function(){
	$(".xzdh").slideUp(500);
		$(".xzdh button em").text("");
		$(".liwu_list li").removeClass("now");
})

function buyGift(){
	if(selGoodsId == null){
		alert("请选择赠送的礼物！");
		return;
	}
	$.ajax({
		url:"../proxy/galaxy/v1/goods/wxbuy/"+liveId+"/"+selGoodsId,
		type:'post',
		dataType:'json',
        contentType: 'application/json;charset=utf-8',
		async: false,
		beforeSend:function(){
	        //请求前的处理
	        $("#buyGiftBtn").removeAttr("onclick");
	    	$(".loading").show();
	    },
		success : function(res) {
			$(".xzdh").slideUp(0);
			$(".xzdh button em").text("");
			$(".liwu_list li").removeClass("now");
			var data = res.channelMap;
			wx.chooseWXPay({
				timestamp: data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
				nonceStr: data.nonceStr, // 支付签名随机串，不长于 32 位
				package: data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
				signType: data.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
				paySign: data.paySign, // 支付签名
				success: function (res) {
					//alert("成功支付");
				}
			});	
		},
		complete:function(){
    		$(".loading").hide();
	        $("#buyGiftBtn").attr("onclick","buyGift()");
	    },
	    error:function(e){
	    	console.error(e);
	    	alert("系统忙，请稍后再试");
        }
	});	
}
/*选择礼物赠送*/
